GBML manual / Strings

string_char_at

The single character at index (0-based), as a one-character string - getting a single character.

Syntax

string_char_at(s, index) -> string

Arguments

NameType
sstring
indexint

Returns

string

Description

The single character at index (0-based), as a one-character string - getting a single character.

index out of range (either side) is an empty string, never a crash. Returned as a string, not a number, so it composes directly with every other function in this group and with ==/< - GBML has no separate character type to convert to or from.

Example

var name = "Ripley";
var initial = string_char_at(name, 0);
var starts_with_r = initial == "R";

string_code_at is its partner: it counts the same way, but hands the character back as a number instead of as text.

Because a character is just a one-character string, a range check reads naturally too: "0" <= c && c <= "9" asks "is c a digit".

On the GBA

index out of range (either side) is an empty string, never a crash. Returned as a string, not a number, so it composes directly with every other function here and with `==`/`<` (e.g. `"0" <= c && c <= "9"` tests "is this character a digit") - GBML has no separate character type to convert to or from.

See also: string_lengthstring_slicestring_code_at